package com.wash.car.web.controller.admin;

import cn.hutool.core.collection.ListUtil;
import com.github.pagehelper.PageInfo;
import com.pmo.boot.common.api.BaseResult;
import com.pmo.boot.common.api.DefaultResult;
import com.wash.car.biz.OrderServer;
import com.wash.car.dao.model.OrderDeleteModel;
import com.wash.car.dao.model.OrderDetailsModel;
import com.wash.car.dao.model.OrderPageWhereModel;
import com.wash.car.dao.model.OrderUpdateModel;
import com.wash.car.web.config.context.UserContext;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = {"订单管理"})
@RestController
@RequestMapping(path = "/admin/order")
public class AdminOrderController {

    @Autowired
    private OrderServer orderServer;


    @ApiOperation(value = "更新订单进度")
    @PostMapping(path = "updateProgress")
    public BaseResult updateProgress(@RequestBody OrderUpdateModel model) {
        orderServer.updateState(model);
        return BaseResult.success();
    }

    @ApiOperation(value = "取消排队")
    @PostMapping(path = "cancelQueue")
    public BaseResult cancelQueue(@RequestBody OrderDeleteModel model) {
        orderServer.del(model);
        return BaseResult.success();
    }


    @ApiOperation(value = "洗车管理")
    @GetMapping(path = "pageCarWashManage")
    public DefaultResult<PageInfo<OrderDetailsModel>> pageCarWashManage(OrderPageWhereModel model) {
        PageInfo<OrderDetailsModel> pageInfo = orderServer.page(model.setStates(ListUtil.toList(new Integer[]{0, 2, 3})));
        return DefaultResult.success(pageInfo);
    }


    @ApiOperation(value = "洗车记录")
    @GetMapping(path = "pageCarWashRecord")
    public DefaultResult<PageInfo<OrderDetailsModel>> pageCarWashRecord(OrderPageWhereModel model) {
        PageInfo<OrderDetailsModel> pageInfo = orderServer.page(model.setStates(ListUtil.toList(new Integer[]{1})));
        return DefaultResult.success(pageInfo);
    }


}
